package org.poseidon.report.service.impl;

import java.util.Calendar;
import java.util.List;
import org.poseidon.common.utils.DateUtils;
import org.poseidon.common.utils.SecurityUtils;
import org.poseidon.report.domain.vo.BuDiaryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.poseidon.report.mapper.BuDiaryMapper;
import org.poseidon.report.domain.BuDiary;
import org.poseidon.report.service.IBuDiaryService;

/**
 * 周报Service业务层处理
 * 
 * @author gfc
 * @date 2022-02-22
 */
@Service
public class BuDiaryServiceImpl implements IBuDiaryService 
{
    @Autowired
    private BuDiaryMapper buDiaryMapper;

    /**
     * 查询周报
     * 
     * @param id 周报主键
     * @return 周报
     */
    @Override
    public BuDiary selectBuDiaryById(Integer id)
    {
        return buDiaryMapper.selectBuDiaryById(id);
    }

    /**
     * 查询周报列表
     * 
     * @param buDiary 周报
     * @return 周报
     */
    @Override
    public List<BuDiaryVO> selectBuDiaryList(BuDiaryVO buDiary)
    {
        return buDiaryMapper.selectBuDiaryList(buDiary);
    }

    /**
     * 新增周报
     * 
     * @param buDiary 周报
     * @return 结果
     */
    @Override
    public int insertBuDiary(BuDiary buDiary)
    {
        buDiary.setCreateTime(DateUtils.getNowDate());
        buDiary.setCreateBy(SecurityUtils.getUsername());
        buDiary.setWeekOfYear(getWeekOfYear());
        return buDiaryMapper.insertBuDiary(buDiary);
    }

    private Integer getWeekOfYear() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.WEEK_OF_YEAR);
    }

    /**
     * 修改周报
     * 
     * @param buDiary 周报
     * @return 结果
     */
    @Override
    public int updateBuDiary(BuDiary buDiary)
    {
        buDiary.setUpdateTime(DateUtils.getNowDate());
        return buDiaryMapper.updateBuDiary(buDiary);
    }

    /**
     * 批量删除周报
     * 
     * @param ids 需要删除的周报主键
     * @return 结果
     */
    @Override
    public int deleteBuDiaryByIds( List<Integer> ids)
    {
        return buDiaryMapper.deleteBuDiaryByIds(ids);
    }

    /**
     * 删除周报信息
     * 
     * @param id 周报主键
     * @return 结果
     */
    @Override
    public int deleteBuDiaryById(Integer id)
    {
        return buDiaryMapper.deleteBuDiaryById(id);
    }

    @Override
    public List<BuDiaryVO> selectiveList(BuDiaryVO buDiary) {
        return buDiaryMapper.selectiveList(buDiary);
    }

    @Override
    public BuDiaryVO selectByPrimaryId(Integer id) {
        return buDiaryMapper.selectByPrimaryId(id);
    }

    @Override
    public int countDiaryByMilestoneList(List<Long> ids) {
        return buDiaryMapper.countDiaryByMilestoneList(ids);
    }

    @Override
    public int countDiaryProjectList(List<Long> ids) {
        return buDiaryMapper.countDiaryProjectList(ids);
    }
}
